package com.capgemini.simpleappblanche.helper;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import com.capgemini.simpleappblanche.domain.customer.Customer;

@Component
public class CustomerHelper {

	private static final String[] SPECIAL_CHAR_FOR_PHONE = new String[]{"/","\\"," ",".",",","-"};
	private static final String[] SPECIAL_CHAR_FOR_PHONE_REPLACEMENT = new String[]{"","","","","",""};
	
	/**
	 * modify customer to save it
	 * @param customer customer
	 * @return customer ready to save
	 */
	public static Customer prepareCustomerToSave(final Customer customer){
		
		customer.setName(CustomerHelper.getName(customer.getName()));
		customer.setFirstname(CustomerHelper.getFirstname(customer.getFirstname()));
		
		return customer;
	}
	
	/**
	 * get name of customer
	 * @param name name of customer
	 * @return modified name
	 */
	public static String getName(final String name){
		return StringUtils.upperCase(name);
	}
	
	/**
	 * get firstName of customer
	 * @param firstname firstName of customer
	 * @return modified firstName
	 */
	public static String getFirstname(final String firstName){
		return StringUtils.capitalize(firstName);
	}

    /**clean value to a phone format
     * @param value value
     * @return value formated
     */
    public static String cleanToPhoneFormat(final String value) {
        String replacedValue = StringUtils.replaceEach(value, SPECIAL_CHAR_FOR_PHONE,SPECIAL_CHAR_FOR_PHONE_REPLACEMENT);
        return replacedValue;
    }
}
